package com.qianf.qfoffice.service.impl;


import com.qianf.qfoffice.dao.DepartDao;
import com.qianf.qfoffice.entity.DepartNum;
import com.qianf.qfoffice.entity.Depart;
import com.qianf.qfoffice.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class DepartServiceImpl implements DepartService {

    @Autowired
    private DepartDao departDao;

    @Override
    public List<Depart> findAllDepart(Integer page, Integer limit) {
        return departDao.findAllDepart();
    }

    @Override
    public int insertDepart(Depart depart) {
        return departDao.insertDepart(depart);
    }

    @Override
    public int deleteDepart(int id) {
        return departDao.deleteDepart(id);
    }

    @Override
    public DepartNum getDepartNum() {
        List<Map> mapList = departDao.getDepartNum();

        List<String> departList = new ArrayList<>();
        List<Integer> departNumList = new ArrayList<>();

        for (Map map : mapList) {
            String departname = (String) map.get("name");
            Long num = (Long) map.get("num");

            departList.add(departname);
            departNumList.add(num.intValue());
        }

        DepartNum departNum = new DepartNum(departList,departNumList);

        return departNum;
    }

    @Override
    public int updateDepart(Depart depart) {
        return departDao.updateDepart(depart);
    }
}
